﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using MN.Framework;
using MN.Framework.MetaData;


namespace MN.Framework.Common
{
    public static class BaseEntityExensions
    {
        public static PropertyInfo PropertyByName(this BaseEntity entity, string propertyName)
        {
            PropertyInfo property = entity.GetType().GetProperty(propertyName);
            if (property == null)
            {
                throw new MnException("Property {0} on entity of type {1} not found", new object[] { propertyName, entity.GetType().Name });
            }
            return property;
        }
        public static string getTitle(this BaseEntity entity)
        {
            EntityHeaderAttribute MyAttribute = (EntityHeaderAttribute)Attribute.GetCustomAttribute(entity.GetType(), typeof(EntityHeaderAttribute));
            return MyAttribute.Title;
        }       

    }
}
